package com.game.battleship;

import java.util.Map;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

import com.game.battleship.db.DbAdapter;

public class UserInfoActivity extends Activity {

	public static final String EXT_USERNAME = "username";
	
	DbAdapter dbAdapter;
	TextView username_TextView;
	Button playNextStage_Button;
	TextView score_TextView;
	TextView nextStage_TextView;
	
	String username;
	int score;
	int nextStage;
	
	public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.user_info);
        
        username_TextView = (TextView)this.findViewById(R.id.username_TextView);
        score_TextView = (TextView)this.findViewById(R.id.score_TextView);
        nextStage_TextView = (TextView)this.findViewById(R.id.nextStage_TextView);
        playNextStage_Button = (Button)this.findViewById(R.id.playNextStage_Button);
        playNextStage_Button.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(UserInfoActivity.this, ArrangeShipsActivity.class);
				intent.putExtra(EXT_USERNAME, username);
				startActivity(intent);
			}
        	
        });
        
        dbAdapter = new DbAdapter(this);
	}
	
	protected void onStart () {
		super.onStart();
		Bundle extras = this.getIntent().getExtras();
		if (extras.containsKey(EXT_USERNAME)) {
			username = extras.getString(EXT_USERNAME);
			username_TextView.setText("Username: " + username);
		}
		
		Map<String, String> map = dbAdapter.getUser(username);
    	score = Integer.parseInt(map.get("score"));
    	score_TextView.setText("Score: " + score);

    	nextStage = Integer.parseInt(map.get("nextStage"));
    	nextStage_TextView.setText("Next Stage: " + nextStage);
	}
}
